package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Product;
import cn.wolfcode.crm.mapper.ProductMapper;
import cn.wolfcode.crm.query.ObjectQuery;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;

    public void save(Product record) {

        productMapper.insert(record);
    }

    public void delete(Long id) {
            productMapper.deleteByPrimaryKey(id);


    }

    public void update(Product record) {
        productMapper.updateByPrimaryKey(record);
    }

    public Product get(Long id) {
        Product product = productMapper.selectByPrimaryKey(id);
        return product;
    }

    public List<Product> getAll() {

        return productMapper.selectAll();
    }

    public PageResult<Product> query(ObjectQuery qo) {
        int totalCount = productMapper.queryForCount(qo);
        if (totalCount == 0) {
            return new PageResult<Product>(totalCount, Collections.<Product>emptyList());
        }


        return new PageResult<Product>(totalCount, productMapper.queryForList(qo));
    }
    //改变保险状态
    public void changState(Long id) {
        productMapper.changState(id);
    }

    //改变不计免赔状态
    public void deductionState(Long id) {
        productMapper.deductionState(id);
    }

    @Override
    public List<Product> queryByOrganizationId(Long id) {
        return productMapper.queryByOrganizationId(id);
    }

    public List<Map> queryProductListByBillId(Long insurancebillId) {

        return productMapper.queryProductListByBillId(insurancebillId);
    }


}
